<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <link rel="stylesheet" href="../css/basic.css">
</head>
<body>
<!-- 展示个人信息 -->
  <div class="layui-container bs-center" >
    <form id="baseInfo" class="layui-form fm-in" lay-filter="">
    	<div class="layui-form-item  bs-hidden">
            <label class="layui-form-label">学生ID号：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_mark" name="stu_mark" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
    	<div class="layui-form-item">
            <label class="layui-form-label">姓名号：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_name" name="stu_name" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_sex" name="stu_sex" required  lay-verify="required" readonly="readonly" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_age"  name="stu_age" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学号：</label>
            <div class="layui-input-block">
            <input type="text" id="stu_no" name="stu_no" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话：</label>
            <div class="layui-input-block">
            <input type="text" id="stu_tel" name="stu_tel" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年级：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_form" name="stu_form" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学院：</label>
            <div class="layui-input-block">
            <input type="text" id="stu_scho" name="stu_scho" required  lay-verify="required|number" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
                <div class="layui-input-block btn-center">
                   <a class="layui-btn" id="iBtn">修改</a>
                </div>
        </div>
    </form>
  </div>

</body>
<!-- 修改学生个人信息 -->
<form id="stuInfo" class="layui-form fm-in bs-hidden" lay-filter="">
    	<div class="layui-form-item bs-hidden">
            <label class="layui-form-label ">学生ID号：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_markB" name="stu_markB" required  lay-verify="required" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
    	<div class="layui-form-item">
            <label class="layui-form-label">姓名：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_nameB" name="stu_nameB" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_sexB" name="stu_sexB" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_ageB"  name="stu_ageB" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学号：</label>
            <div class="layui-input-block">
            <input type="text" id="stu_noB" name="stu_noB" required readonly lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话：</label>
            <div class="layui-input-block">
            <input type="text" id="stu_telB" name="stu_telB" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年级：</label>
            <div class="layui-input-block">
                <input type="text" id="stu_formB" name="stu_formB" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学院：</label>
            <div class="layui-input-block">
            <input type="text" id="stu_schoB" name="stu_schoB" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block btn-center">
            <button class="layui-btn" lay-submit lay-filter="updatePwd">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
        </div>
    </form>
<span class="bs-hidden" id="Sid"></span>
<script>
 layui.use(['laydate','form','jquery','layer','table'], function(){
  var laydate = layui.laydate;
  var form = layui.form
  var $ = layui.jquery
  var layer = layui.layer
  var table = layui.table;
  //自定义验证规则
  form.verify({
    //为账号定义的验证添加规则
  })
$.ajax({
  	type:"POST",
  	url:"/user/getStuUser",
  	dataType:"json",
  	error:function(){
  		console.log("error!");
  	},
  	success:function(data){
  		$('#Sid').html(data.stu_no);
  		ajaxNO1();
  	}
  })
function ajaxNO1(){
  $.ajax({
	  type:"GET",
	  url:'/student/serchMessage',
	  data:{"stu_no":$('#Sid').text()},
	  error:function(XMLHttpRequest, textStatus, errorThrown){
		  alert(XMLHttpRequest+'    '+textStatus+"    说明服务器返回失败");
	  },
	  dataType:"json",
	  success:function(data){
		console.log(data);
		$('#stu_mark').val(data.stu_mark);
		$('#stu_name').val(data.stu_name);
		$('#stu_sex').val(data.stu_sex);
		$('#stu_age').val(data.stu_age);
		$('#stu_no').val(data.stu_no);
		$('#stu_tel').val(data.stu_tel);
		$('#stu_form').val(data.stu_form);
		$('#stu_scho').val(data.stu_scho);
		
		$('#stu_markB').val(data.stu_mark);
		$('#stu_nameB').val(data.stu_name);
		$('#stu_sexB').val(data.stu_sex);
		$('#stu_ageB').val(data.stu_age);
		$('#stu_noB').val(data.stu_no);
		$('#stu_telB').val(data.stu_tel);
		$('#stu_formB').val(data.stu_form);
		$('#stu_schoB').val(data.stu_scho);
	  }
  })
}
//  ajaxNO1();
  $("#iBtn").click(function(){
      layer.open({
          title:'个人信息修改',
          offset: '10px',
          type:1,
          content:$('#stuInfo'),
          area:['800px','650px'],
      });
  })
  //监听提交
  form.on('submit(updatePwd)', function(data){
    console.log(data.field);
    $.ajax({
    	type:"GET",
    	url:"/student/changeMessage",
    	data:{
    		stu_name:data.field.stu_nameB,
    		stu_sex:data.field.stu_sexB,
    		stu_age:data.field.stu_ageB,
    		stu_no:data.field.stu_noB,
    		stu_tel:data.field.stu_telB,
    		stu_form:data.field.stu_formB,
    		stu_scho:data.field.stu_schoB	
    	},
    	dataType:"json",
    	error:function(){
    		alert("error!");
    	},
    	success:function(data){
    		console.log(data);
    		if(data == true){
    			layer.msg('修改成功!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			
    			ajaxNO1();
    			return false;
    		}else if(data == false){
    			layer.msg('修改失败!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			ajaxNO1();
    			return false;
    		}
    	}	
    })
    return false;
  });
})
</script>
</html>

